  function InitiliazeSessionStatus(){
                                
            var sitestatus_date = new Date();
            var hours = sitestatus_date.getHours();
            var minutes = sitestatus_date.getMinutes();
 
            var suffix = "am";
            if (hours >= 12) {
                suffix = "pm";
                hours = hours - 12;
            }
            if (hours == 0) {
                hours = 12;
            }
            
            if (minutes < 10)
                minutes = "0" + minutes;
            
			var statusText = (hours + ":" + minutes + suffix + " | " + 
							  sitestatus_date.toDateString() + " | " + 
							  (navigator.cookieEnabled ? "Cookies active" : "Cookies inactive"));
			$("#visit_info").text(statusText);
        }
		
		
 function reloateViewpane(urlLocal) {
	$.ajax({
	  url: urlLocal,
	  cache: false,
	  beforeSend: function(XMLHttpRequest) {

	  },
	  error: function(XMLHttpRequest, textStatus, errorThrown) {
		  
	  },
	  success: function(html){
	    $("#dacretest").fadeOut(200, function() {								  
	    $("#dacretest").html(html).fadeIn(200);
		});
	  }
	});
	 
 }
 
function FixCalender($contentNode) {     
var funcChangeMonth = function(url) {

	$calenderElements.fadeOut("fast",function() {
			$.ajax({
			  url: url,
			  cache: true,
			  error: function(XMLHttpRequest, textStatus, errorThrown) {
				  alert('error');
				  },
			  success: function(html){	
				$calenderElements.html("");
				$calenderElements.html(html);
				FixCalender($calenderElements);
				//$calenderElements.fadeIn("fast");
				//$calenderElements.show();
				}
			});
		});
	
	}
	$calenderElements = $("* > .calendarContainer",$contentNode);
	$("* > .event",$calenderElements).hide();
	
	var $eventInformation = $("* > #eventInfo",$calenderElements);
	var $eventDates = $("* > .eventDate",$calenderElements);
	
	$eventInformation.hide();
	
	$eventDates.mouseenter(function() {

var $eventInfoDiv = $("* > .event", $(this)).eq(0);
var eventName = $("*", $eventInfoDiv).eq(1).text();
var eventDate = $("*", $eventInfoDiv).eq(2).text();

$eventInformation.html( eventName  + "<br>" + eventDate );

		$(this).addClass('hover'); 
		$eventInformation.show();
	});

	$eventDates.mouseleave(function() {      

		$(this).removeClass('hover');
		$eventInformation.hide();
	});

	$eventDates.click(function() {     

var $eventInfoDiv = $("* > .event", $(this)).eq(0);
var $eventLinkInfo = $("*", $eventInfoDiv).eq(0);
var eventLink = $eventLinkInfo.attr('href');
funcChangeMonth(eventLink);
	//var $navLinks = $("* > .calendarNavLink",$calenderElements);

        //    $("#calender_dock_panel").hide('blind',400); 

//		$(this).toggleClass('clicked');
	});
	
	var $navLinks = $("* > .calendarNavLink",$calenderElements);
	var $nextMonth = $navLinks.eq(0);
	var $prevMonth = $navLinks.eq(1);
	$nextMonth.hide();
	$prevMonth.hide();	

	var $nextURL = $nextMonth.attr('href');
	var $prevURL = $prevMonth.attr('href');

	var funcShortenDayName = function() {
		var $labelText = jQuery.trim($(this).text()).slice(0,3);
		$(this).text($labelText);
		$(this).css('width', '40px');
	}

	
	 

	jQuery.each($('.date'), function() {
		if($(this).children().length > 2)
			$(this).children().eq(0).css('color', 'white');
	});
	jQuery.each($(".dayLabelWeekend"),funcShortenDayName );
	jQuery.each($(".dayLabel"),funcShortenDayName );

	$navLinks.attr('href', '#'); 
	$nextMonth.click( function() { funcChangeMonth($nextURL); } );	 
	$prevMonth.click( function() { funcChangeMonth($prevURL); } );	 	

	$nextMonth.show();
	$prevMonth.show();	
	$contentNode.fadeIn("fast");

}
 
function InitializeDesign() {
        $("#left_panel_toggle").toggle(function() {
												
                if(g_menuMapOpen)
                    closeMenumap();
 
                $(".left_panel").animate({  left: -170 }, 200);
                $(".body").animate({ left: 25 }, 200);                
            },
            function() {
                $(".left_panel").animate({ left: 0}, 200);
                $(".body").animate({ left: 195 }, 200);                
            }
        );    
        
        /*
        Setup left menu buttons
        */
        $(".menu_button").addClass('inactive');
        $(".menu_button").mouseenter(function() {
 
            $(this).addClass('hover');                    
        });
        $(".menu_button").mouseleave(function() {      
 
            $(this).removeClass('hover');
        });
        $(".menu_button").click(function() {      
 
            $(this).toggleClass('clicked');
        });
            
                                
        $(".dock").sortable({
            connectWith: '.dock'
        }); 
        
        $(".dock").bind('sortreceive', function(event, ui) {
updatePortletCookies();
        });                   
 
        $(".portlet").addClass("ui-widget ui-widget-content ui-helper-clearfix ")
            .find(".portlet-header")
                .addClass("ui-widget-header ui-corner-all")
                .prepend('<span class="ui-icon ui-icon-plusthick"></span>')
                .end()
            .find(".portlet-content");
 
        $(".portlet-header .ui-icon").click(function() {
            $(this).toggleClass("ui-icon-minusthick");
            $(this).parents(".portlet:first").find(".portlet-content").toggle();
        });
 
        $(".column").disableSelection();
		
		$("#calender_dock_panel").hide();
    

        $("#calender_dock").toggle(function() {

			$.ajax({
/*
				url: "./testcal",
*/
				url: "http://cosi-test.scms.waikato.ac.nz/testcal",
				cache: false,
				error: function(XMLHttpRequest, textStatus, errorThrown){
					$("#calender_dock_panel").html('An error occoured (' + textStatus + ')');
					},
				success: function(html){	
					$("#calender_dock_panel").html(html);
					FixCalender($("#calender_dock_panel"));
				}
				});
	            $("#calender_dock_panel").show('blind',400);
			},
			
			function() {
			    $("#calender_dock_panel").hide('blind',400);
			}
		);
		/////////////////////////
		
			
	   $("#projects_button").click(function() {
 
						
            if(g_menuMapOpen) {
                
                g_menuMapOpen = false;
                $("#menumap").hide('slide',400);
            }
            else {
                g_menuMapOpen = true;
                $("#menumap").show('slide',400);
            }
        });
		
        $("#welcome_button").click(function() {

			reloateViewpane("./welcome.html");
        });
		
        $("#news_button").click(function() {

			reloateViewpane("./news.html");
        });
		
        $("#events_button").click(function() {

			reloateViewpane("./events.html");
        });
		
        $("#help_button").click(function() {

			reloateViewpane("./help.html");
        }); 
		
		
		$("#cosi_search").focus( function() {
        $("#cosi_search").val('');
        $("#cosi_search").css({'color' : '#333', 'font-style' : 'normal'});        
        });
}